//
//  SummaryViewController.m
//  MM
//
//  Created by 郑渊文 on 6/3/15.
//  Copyright (c) 2015 王晨辉. All rights reserved.
//

#import "SummaryViewController.h"
#import "EvaluateViewController.h"
#import "ReadEvaluationViewController.h"


@interface SummaryViewController ()<UITextViewDelegate>
{
UITextView *introduceLable;
    UIButton *backBtn;
}
@property(nonatomic,copy)NSString *DetailText;
@property(nonatomic,assign)int ifsug;
@end

@implementation SummaryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSDictionary *param4 = @{@"classId":_classId,@"userId":@"1"};
    
    [UserDAL getClasssummaryParams:param4 withBlock:^(NSDictionary *data, NSError *error) {
        if (data) {
            ////NSLog(@"what%@",data);
            _DetailText = data[@"classsummary"];
            _ifsug = [data[@"ifsendSug"]intValue];
            //            for (NSDictionary *mydic in array) {
            //
            //            }
            
            
        }else
        {
            
        }
    }];

//    _DetailText= @"Acting as if nothing borne in mind is the best revenge.It's all for myself to live better.Every day may not be good…but there's something good in every day.Happiness is about having each tiny wish come ture.A woman has got to love a bad man once or twice in her life to be thankful for a good one.";
    
    [self initSubViews];
    self.navigationItem.title = @"课程详情";
    [self.navigationController.navigationBar setTranslucent:NO];//设置navigationbar的半透明
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#34bd81" alpha:1]];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];

    //    self.navigationItem.rightBarButtonItem.title = @"课程详情";
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)viewDidAppear:(BOOL)animated
{
    introduceLable.text = _DetailText;
}

-(void)initSubViews
{
    
    
    //自定义左右按钮
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
     
                      forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(back)
     
     forControlEvents:UIControlEventTouchUpInside];
    
    button.frame = CGRectMake(0, 0, 20, 15);
    
    
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    
    
    self.navigationItem.leftBarButtonItem = menuButton;
    
    
    
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self.view addSubview:bgView];
    bgView.backgroundColor = [UIColor whiteColor];
    
    UILabel *intrTitle = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-100, 10, 200, 60)];
    intrTitle.text = @"课程总结";
    intrTitle.textAlignment = NSTextAlignmentCenter;
    intrTitle.font  = [UIFont systemFontOfSize:25];
    intrTitle.textColor = [UIColor blackColor];
    [bgView addSubview:intrTitle];
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 70, SCREEN_WIDTH, 1)];
    lineView.backgroundColor = UIColorWithRGBA(215, 215, 215, 1);
    [bgView addSubview:lineView];
    
    introduceLable = [[UITextView alloc]initWithFrame:CGRectMake(10, 80, SCREEN_WIDTH-20, SCREEN_HEIGHT-100)];
//    introduceLable.numberOfLines = 0;
    introduceLable.editable = NO;
    introduceLable.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高度
    introduceLable.font = [UIFont fontWithName:@"Helvetica" size:13];

    
    
//    NSString *text = _DetailText;
//    UIFont *font = [UIFont fontWithName:@"Helvetica" size:13.0];
//    CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(SCREEN_WIDTH-20, 2000.0f)
//                       lineBreakMode:NSLineBreakByWordWrapping];
//    CGRect rect = introduceLable.frame;
//    rect.size = size;
//    float viewHeight = size.height;
//    [introduceLable setFrame:rect];
//    [introduceLable setText:text];
//    
//    UIView *introduceView = [[UIView alloc]initWithFrame:CGRectMake(10, 80, SCREEN_WIDTH-20, 40+viewHeight)];
//    introduceView.backgroundColor = [UIColor whiteColor];
//    introduceView.layer.borderColor = [UIColor clearColor].CGColor;
//    introduceView.backgroundColor = [UIColor whiteColor];
//    introduceView.layer.borderWidth = 1;
    
//    [bgView addSubview:introduceView];
//    [introduceView addSubview:introduceLable];
    [bgView addSubview:introduceLable];
    
    UIButton *myBtn = [[UIButton alloc]initWithFrame:CGRectMake(50, SCREEN_HEIGHT-150, SCREEN_WIDTH-100, 40)];
    [myBtn setTitle:@"马上/查看评价" forState:UIControlStateNormal];
    [myBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [myBtn addTarget:self action:@selector(doorToTeach) forControlEvents:UIControlEventTouchUpInside];
    myBtn.backgroundColor = UIColorWithRGBA(227, 90,92, 1);
    [bgView addSubview:myBtn];
    
}

//#pragma mark - UITextViewDelegate
//- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
//{
//    if([introduceLable isFirstResponder]){
//        return YES;
//    }
//    return NO;
//}

-(void)doorToTeach
{
    ////NSLog(@"ifsug是%d",_ifsug);
    ReadEvaluationViewController *setVC = [[ReadEvaluationViewController alloc]init];
    setVC.classId = self.classId;
    EvaluateViewController *evaluateVC = [[EvaluateViewController alloc]init];
    if (_ifsug == 0) {
        UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:evaluateVC];
        [self  presentViewController:nav animated:YES completion:nil];
    }else if(_ifsug == 1)
    {
        UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:setVC];
        [self  presentViewController:nav animated:YES completion:nil];
    }
    else if(_ifsug == -1)
    {
        
    }

    
}

-(void)back
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

@end
